﻿@model IEnumerable<System.Data.DataRow>
@foreach (var i in Model)
{
    <div id="IBox0" class="IBox">
        <div title="" style="" class="Form_Msg" id="Message0">
        </div>
        <div class="ItemName" style="">
            @i["qorder"]、 @i["qtitle"]</div>
        <div style="">
            @{ var answers = Diaocha.Controllers.VoteController.GetAnswer(Convert.ToInt32(i["questionid"])); }
            @if (i["qtype"].ToString() == "radio")
            {
                <table>
                    <tbody>
                        @foreach (var a in answers)
                        {
                            <tr>
                                <td>
                                    <input name="q@{@i["questionid"]}" value="@a["answerid"]" class="radio" type="radio" />
                                    <span class="OptionName">
                                        <label>@a["atitle"]</label>
                                    </span>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            }
            else if (i["qtype"].ToString() == "check")
            {
                <table>
                    <tbody>
                        @foreach (var a in answers)
                        {
                            <tr>
                                <td>
                                    <input name="q@{@i["questionid"]}" value="@a["answerid"]" class="check" type="checkbox" />
                                    <span class="OptionName">
                                        <label>@a["atitle"]</label>
                                    </span>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            }
            else if (i["qtype"].ToString() == "input")
            {
                <table>
                    <tbody>
                        <tr>
                            <td>
                                <textarea name="q@{@i["questionid"]}" cols="60" rows="5"></textarea>
                            </td>
                        </tr>
                    </tbody>
                </table>
            }
            else if (i["qtype"].ToString() == "mradio")
            {
                <table class="tborder">
                    <tbody>
                        @{var xcolumns = answers.Select(r => r["xtitle"]).Distinct(); }
                        <tr>
                            <td style="width: 20%; border: solid #eee 1px;">
                            </td>
                            @foreach (var x in xcolumns)
                            {
                                <td style="width: 13%; border: solid #eee 1px;">@x
                                </td>
                            }
                        </tr>
                        @{var ygroups = answers.GroupBy(r => r["ytitle"]); }
                        @foreach (var group in ygroups)
                        {
                            <tr>
                                <td style="border: solid #eee 1px;">
                                    @group.Key
                                </td>
                                @foreach (var option in group)
                                {
                                    var order = Convert.ToInt32(option["aorder"]);
                                    int index = 0;
                                    if (order > 100)
                                    { index = order % 100; }
                                    else
                                    { index = order % 10; }
                                   
                                    <td style="border: solid #eee 1px;">
                                        <input type="radio" name="q@{@i["questionid"]}_@{@index}" value="@option["answerid"]" />
                                    </td>
                                }
                            </tr>
                        }
                    </tbody>
                </table>
            }
        </div>
    </div>
    <div class="ItemBlank">
    </div>
}